// @ts-nocheck
import _ from "lodash";
import {useState} from "react";
import {Button, Row, Table} from "antd";
import {orderGetList} from "@/api";
import {useList, useBoolean} from "@/hooks";
import {columnImage, getColumnsId} from "@/components/Columns";
import {Tooltips} from "@/components/common";
import {useNavigate} from "react-router-dom";

const GoodsList = () => {
    const nav = useNavigate();
    const [subOrderNumber, setSubOrderNumber] = useState("");
    const [promotionPositionId, setPromotionPositionId] = useState("");
    const [orderStatus, setOrderStatus] = useState("");
    const [createTimeStart, setCreateTimeStart] = useState("");
    const [createTimeEnd, setCreateTimeEnd] = useState("");

    const {
        data: {list, pageNum, pageSize, total},
        pagingChange,
        refresh,
    } = useList(
        {
            api: orderGetList,
            params: {
                subOrderNumber,
                promotionPositionId,
                orderStatus,
                createTimeStart,
                createTimeEnd,
            },
        },
        [subOrderNumber, promotionPositionId, createTimeStart, createTimeEnd, orderStatus]
    );

    const handleAddGoods = () => {
        nav("/home/goods/add");
    };

    const columns = [
        getColumnsId({pageNum, pageSize}),
        {
            title: "商品名称",
            dataIndex: "productTitle",
            key: "productTitle",
            width: 200,
            render: val => <Tooltips title={val} width={150} />,
        },
        columnImage,
        {title: "商品分类", dataIndex: "a", key: "a"},
        {title: "1688url", dataIndex: "a", key: "a"},
        {title: "1688批发价格", dataIndex: "a", key: "a"},
        {title: "最低批发数量", dataIndex: "a", key: "a"},
        {title: "一件代发价格", dataIndex: "a", key: "a"},
        {title: "售卖价格", dataIndex: "a", key: "a"},
        {title: "积分兑换", dataIndex: "a", key: "a"},
        {title: "是否上下架", dataIndex: "a", key: "a"},
        {
            title: "操作",
            dataIndex: "index",
            render: () => (
                <Button type="primary" size="small">
                    详情
                </Button>
            ),
        },
    ];

    return (
        <div className="order-list">
            <Table
                title={() => (
                    <Row>
                        <Button type="primary" onClick={handleAddGoods}>
                            添加商品
                        </Button>
                    </Row>
                )}
                rowKey={row => JSON.stringify(row)}
                pagination={{current: pageNum, pageSize, showSizeChanger: true, total}}
                dataSource={list}
                columns={columns}
                onChange={pagingChange}
            />
        </div>
    );
};

export default GoodsList;
